<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-ability__bsabilityservice">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.name" placeholder="名称" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.type" placeholder="分类 ab_info">
            <el-option label="选择" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.deptId" placeholder="部门">
            <el-option label="选择" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="info" @click="exportHandle()">{{ $t('export') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('ability:bsabilityservice:save')" type="primary" @click="addOrUpdateHandle()">挂接</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('ability:bsabilityservice:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="name" label="名称" header-align="center" align="center"></el-table-column>
        <el-table-column prop="subtext" label="简单介绍" header-align="center" align="center" width="280"></el-table-column>
        <el-table-column prop="imgurl" label="图标" header-align="center" align="center">
          <template slot-scope="scope">
            <svg class="icon-svg" aria-hidden="true"><use :xlink:href="`#${scope.row.imgurl}`"></use></svg>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="img" label="展示图片" header-align="center" align="center"></el-table-column> -->
        <el-table-column prop="shareForm" label="共享方式" header-align="center" align="center"></el-table-column>
        <el-table-column prop="deptId" label="部门" header-align="center" align="center"></el-table-column>
        <el-table-column prop="field" label="领域" header-align="center" align="center"></el-table-column>
        <el-table-column prop="updateDate" label="更新时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="isUp" label="是否推荐" header-align="center" align="center" :formatter="isUpformatter"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('ability:bsabilityservice:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('ability:bsabilityservice:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
            <el-button type="text" size="small" @click="showDetail(scope.row.id)">展示</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update :disabled="disabled" v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './bsabilityservice-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/ability/bsabilityservice/page',
        getDataListIsPage: true,
        exportURL: '/ability/bsabilityservice/export',
        deleteURL: '/ability/bsabilityservice',
        deleteIsBatch: true
      },
      disabled: false,
      dataForm: {
        name: '',
        type: '',
        deptId: ''
      }
    }
  },
  watch: {
  },
  components: {
    AddOrUpdate
  },
  methods: {
    isUpformatter (row, column, cellValue, index) {
      console.log(row, column, cellValue, index)
      if (cellValue == 1) {
        return '是'
      } else if (cellValue == 0) {
        return '否'
      } else {
        return ''
      }
    },
    showDetail (id) {
      this.addOrUpdateHandle(id)
      this.disabled = true
    }
  }
}
</script>
